home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 037a / tpfast40.zip / TPFFILE.ASM < prev    next >
Assembly Source File  |  1991-11-14  |  15KB  |  330 lines

  1. ;   _______________________________________________________________
  2. ;  |                                                               |
  3. ;  |            CopyRight (c) 1989,1990  Steven Lutrov             |
  4. ;  |_______________________________________________________________|____
  5. ;  |                                                               |    |
  6. ;  |  program title : fastfile.asm                                 |    | ___
  7. ;  |  author        : Steven Lutrov                                |    |    |
  8. ;  |  revision      : 2.02                                         |    |    |
  9. ;  |  date          : 1991-11-01                                   |    |    |
  10. ;  |  language      : turbo assembler                              |    |    |
  11. ;  |                                                               |    |    |
  12. ;  |                                                               |    |    |
  13. ;  |  description   : assembly functions for primitive file        |    |    |
  14. ;  |                : handeling.                                   |    |    |
  15. ;  |                : tested on turbo pascal turbo pascal 5.5      |    |    |
  16. ;  |                                                               |    |    |
  17. ;  |_______________________________________________________________|    |    |
  18. ;      |                                                                |    |
  19. ;      |________________________________________________________________|    |
  20. ;          |                                                                 |
  21. ;          |_________________________________________________________________|
  22. ;
  23.  
  24.  
  25.  
  26. code segment word public
  27.  
  28. assume cs:code,ds:data
  29.  
  30.  
  31. public fclose,fcreate,ferase,fseek,fopen,fread,
  32. public fwrite,getverify,readsector,setverify,writesector
  33.  
  34.  
  35.  
  36. ;-------------------------------------------------------------------------------
  37. ;function getverify: boolean;
  38. ;-------------------------------------------------------------------------------
  39. ;
  40. getverify proc far
  41.         mov  ah,54h                     ;dos func to get verify
  42.         int  21h                        ;get status
  43.         ret
  44. getverify endp
  45.  
  46.  
  47. ;-------------------------------------------------------------------------------
  48. ;procedure readsector(segment,offset,drive,sector,number: word);
  49. ;-------------------------------------------------------------------------------
  50. ;
  51. data    segment
  52.         extrn  TPFError :byte
  53. data    ends
  54. ;
  55. ;
  56. readsector proc far
  57.                 push  bp                        ;save bp
  58.                 mov   bp,sp                     ;set up stack frame
  59.                 push  ds                        ;save ds
  60.                 lds   bx,dword ptr[bp+12]       ;get buffer address
  61.                 mov   al,[bp+10]                ;drive code
  62.                 dec   al                        ;adjust for turbo
  63.                 mov   dx,[bp+8]                 ;logical sector number
  64.                 mov   cx,[bp+6]                 ;number sectors to read
  65.                 int   25h                       ;read the sector(s)
  66.                 mov   bl,0                      ;0 = no error
  67.                 jnc   rsec1                     ;test for error
  68.                 mov   bl,ah                     ;error code to bl
  69. rsec1:          pop   cx                        ;balance stack
  70.                 pop   ds                        ;restore ds
  71.                 pop   bp                        ;restore bp
  72.                 mov   TPFError,bl              ;set error code
  73.                 ret   10
  74. readsector endp
  75.  
  76.  
  77. ;-------------------------------------------------------------------------------
  78. ;procedure setverify(setting: boolean);
  79. ;-------------------------------------------------------------------------------
  80. ;
  81. setverify proc far
  82.                 mov  bx,sp                      ;
  83.                 sub  dl,dl                      ;dl must = 0
  84.                 mov  al,ss:[bx+4]               ;1 = on, 0 = off
  85.                 mov  ah,2eh                     ;dos func to set verify
  86.                 int  21h                        ;set verification
  87.                 ret  2
  88. setverify endp
  89.  
  90.  
  91. ;-------------------------------------------------------------------------------
  92. ;procedure writesector(segment,offset,drive,sector,number: word;);
  93. ;-------------------------------------------------------------------------------
  94. ;
  95. data    segment
  96.         extrn  TPFError :byte
  97. data    ends
  98. ;
  99. ;
  100. writesector proc far
  101.                 push  bp                        ;save bp
  102.                 mov   bp,sp                     ;set up stack frame
  103.                 push  ds                        ;save ds
  104.                 lds   bx,dword ptr[bp+12]       ;get buffer address
  105.                 mov   al,[bp+10]                ;drive code
  106.                 dec   al                        ;adjust for turbo
  107.                 mov   dx,[bp+8]                 ;logical sector number
  108.                 mov   cx,[bp+6]                 ;number sectors to write
  109.                 int   26h                       ;write the sector(s)
  110.                 mov   bl,0                      ;0 = no error
  111.                 jnc   wsec1                     ;test for error
  112.                 mov   bl,ah                     ;error code to bl
  113. wsec1:          pop   cx                        ;balance stack
  114.                 pop   ds                        ;restore ds
  115.                 pop   bp                        ;restore bp
  116.                 mov   TPFError,bl              ;set error code
  117.                 ret   10                        ;
  118. writesector endp
  119.  
  120. ;-------------------------------------------------------------------------------
  121. ;function fcreate(fname:string; attribute :integer) :integer;
  122. ;-------------------------------------------------------------------------------
  123. ;
  124. fcname     equ        dword ptr [bp+8]
  125. fcattr     equ        word  ptr [bp+6]
  126. fcsize     equ        4 + 2
  127.  
  128. fcreate    proc far
  129.                 push bp                      ; save bp
  130.                 mov  bp,sp                   ; setup stack frame
  131.                 push ds                      ; save ds
  132.                 lds  si,fcname               ; get fcname address
  133.                 mov  bl,[si]                 ; get length of string in dx
  134.                 inc  si                      ; skip pascal string[0] length byte
  135.                 xor  bh,bh                   ; bx=$00xx, where xx is length
  136.                 mov  [si+bx],bh              ; end string with asciz
  137.                 mov  dx,si                   ; fname asciz ptr in ds:dx
  138.                 mov  cx,fcattr               ; attribute to set in created file
  139.                 mov  ah,3ch                  ; create
  140.                 int  21h                     ; do it
  141.                 jnc  fc01                    ; jump if no error
  142.                 neg  ax                      ; ax:=-ax
  143. fc01:           pop  ds                      ;
  144.                 pop  bp                      ;
  145.                 ret  fcsize
  146. fcreate    endp
  147.  
  148. ;-------------------------------------------------------------------------------
  149. ;function fopen(name:string; access :integer) :integer;
  150. ;-------------------------------------------------------------------------------
  151. ;
  152. foname     equ        dword ptr [bp+8]
  153. foacce     equ        word  ptr [bp+6]
  154. fosize     equ        4 + 2
  155.  
  156. fopen      proc far
  157.                 push bp                      ; save bp
  158.                 mov  bp,sp                   ; set up stack frame
  159.                 push ds                      ; save ds
  160.                 lds  si,foname               ; get foname address
  161.                 mov  bl,[si]                 ; get length of string in dx
  162.                 inc  si                      ; skip pascal string[0] length byte
  163.                 xor  bh,bh                   ; bx=$00xx, where xx is length
  164.                 mov  [si+bx],bh              ; end string with asciz
  165.                 mov  dx,si                   ; fname asciz ptr in ds:dx
  166.                 mov  ax,foacce               ; file access code
  167.                 mov  ah,3dh                  ; open file
  168.                 int  21h                     ; do it
  169.                 mov  bx,0                    ; boolean false
  170.                 jnc  fo01                    ; jump if no error
  171.                 neg  ax                      ; ax:=-ax;
  172. fo01:           pop  ds                      ; restore ds
  173.                 pop  bp                      ; restore bp
  174.                 ret  fosize
  175. fopen      endp
  176.  
  177.  
  178.  
  179. ;-------------------------------------------------------------------------------
  180. ;function fclose(handle :integer):boolean;
  181. ;-------------------------------------------------------------------------------
  182. ;
  183. fclhandle  equ  word ptr [bp+6]
  184. fclsize    equ  2
  185.  
  186. fclose     proc far
  187.                 push bp                      ; save bp stack
  188.                 mov  bp,sp                   ; set up stack frame
  189.                 mov  bx,fclhandle            ; file handler identifier
  190.                 mov  ah,3eh                  ; close
  191.                 int  21h                     ; do it
  192.                 mov  ax,0                    ; boolean false
  193.                 jc   fcl01                   ; jump if error
  194.                 mov  ax,1                    ; boolean true
  195. fcl01:          pop  bp
  196.                 ret  fclsize
  197. fclose     endp
  198.  
  199.  
  200.  
  201. ;-------------------------------------------------------------------------------
  202. ;function fwrite(handle :integer; nwrite:word; var buff) :integer;
  203. ;-------------------------------------------------------------------------------
  204. ;
  205. fwhandle   equ  word ptr [bp+12]
  206. fwwrite    equ  word ptr [bp+10]
  207. fwbuff     equ  dword ptr [bp+6]
  208. fwsize     equ  2 + 2 + 4
  209.  
  210. fwrite     proc far
  211.                 push bp                      ; save bp stack
  212.                 mov  bp,sp                   ; set up stack frame
  213.                 push ds                      ; save ds
  214.                 mov  bx,fwhandle             ; file handler identifier
  215.                 lds  dx,fwbuff               ; data buffer
  216.                 mov  cx,fwwrite              ; number of bytes to write
  217.                 cmp  cx,07fffh               ; above 7fff
  218.                 ja   fw02                    ; to many bytes to write
  219.                 mov  ah,40h                  ; write
  220.                 int  21h                     ; do it
  221.                 jnc  fw01                    ; jump if no error
  222. fw02:           neg  ax                      ; ax:=-ax;
  223. fw01:           pop  ds                      ; restore bs
  224.                 pop  bp                      ; restore bp
  225.                 ret  fwsize
  226. fwrite     endp
  227.  
  228.  
  229. ;-------------------------------------------------------------------------------
  230. ;function fread(handle:word; amount:word; var buff) :integer;
  231. ;-------------------------------------------------------------------------------
  232. ;
  233. frhandle   equ  word ptr [bp+12]
  234. framount   equ  word ptr [bp+10]
  235. frbuff     equ  dword ptr [bp+6]
  236. frsize     equ  2 + 2 + 4
  237.  
  238. fread      proc far
  239.                 push bp                      ; store bp
  240.                 mov  bp,sp                   ; setup stack frame
  241.                 push ds                      ; save ds
  242.                 mov  bx,frhandle             ; file handler identifier
  243.                 lds  dx,frbuff               ; data buffer
  244.                 mov  cx,framount               ; number of bytes to read
  245.                 cmp  cx,07fffh               ; above 7fff
  246.                 ja   fr02                    ; too many bytes to read
  247.                 mov  ah,3fh                  ; read
  248.                 int  21h                     ; do it
  249.                 jnc  fr01                    ; jump if no error
  250. fr02:           neg  ax                      ; make ax negative
  251. fr01:           pop  ds                      ; restore ds
  252.                 pop  bp                      ; restore bp
  253.                 ret  frsize
  254. fread      endp
  255.  
  256.  
  257. ;-------------------------------------------------------------------------------
  258. ;function fseek(handle :integer; mode :integer; offset:longint;
  259. ;                      var location:longint):boolean;
  260. ;-------------------------------------------------------------------------------
  261. ;
  262. fshandle   equ  word ptr [bp+16]
  263. fsmode     equ  word ptr [bp+14]
  264. fsofshi    equ  word ptr [bp+12]
  265. fsofslo    equ  word ptr [bp+10]
  266. fslocation equ  dword ptr [bp+6]
  267.  
  268. fssize     equ  2 + 2 + 4 + 4
  269.  
  270. fseek      proc far
  271.                 push bp                      ; save bp
  272.                 mov  bp,sp                   ; set up stack frame
  273.                 push ds                      ; save ds
  274.                 mov  bx,fshandle             ; file handler identifier
  275.                 mov  cx,fsofshi              ; file offset in cx
  276.                 mov  dx,fsofslo              ; file offset in cx:dx
  277.                 mov  ax,fsmode               ; load method code
  278.                 mov  ah,42h                  ; seek
  279.                 int  21h                     ; do it
  280.                 mov  bx,1                    ; boolean true
  281.                 jnc  fs01                    ; jump if not error
  282.                 mov  bx,0                    ; boolean false
  283.                 mov  dx,0                    ; high word in location=$0000
  284. fs01:           les  di,fslocation           ; point to fslocation
  285.                 cld                          ; set direction flag
  286.                 stosw                        ; low word to location
  287.                 mov  ax,dx                   ;
  288.                 stosw                        ; high word to location
  289.                 mov  ax,bx                   ; return false or true
  290.                 pop  ds                      ; restore ds
  291.                 pop  bp                      ; restore bp
  292.                 ret  fssize
  293. fseek      endp
  294.  
  295.  
  296.  
  297. ;-------------------------------------------------------------------------------
  298. ;function ferase(name:string) :integer;
  299. ;-------------------------------------------------------------------------------
  300. ;
  301. fename     equ  dword ptr [bp+6]
  302. fesize     equ  4
  303.  
  304. ferase     proc far
  305.                 push bp                      ; save bp
  306.                 mov  bp,sp                   ; set up stack frame
  307.                 push ds                      ; save ds
  308.                 lds  si,fename               ; get address of fename
  309.                 mov  bl,[si]                 ; get length of string in dx
  310.                 inc  si                      ; skip pascal string[0] length byte
  311.                 xor  bh,bh                   ; bx=$00xx, where xx is length
  312.                 mov  [si+bx],bh              ; end string with asciz
  313.                 mov  dx,si                   ; fname asciz ptr in ds:dx
  314.                 mov  ah,41h                  ; erase file
  315.                 int  21h                     ; do it
  316.                 mov  bx,0                    ; boolean false
  317.                 jnc  fe01                    ; jump if no error
  318.                 neg  ax                      ; make ax -ax;
  319.                 jmp  fe02                    ; restore and exit
  320. fe01:           mov  ax,0                    ;
  321. fe02:           pop  ds                      ; restore ds
  322.                 pop  bp                      ; restore bp
  323.                 ret  fesize
  324. ferase     endp
  325.  
  326.  
  327. code    ends
  328.         end
  329.  
  330.